package com.doubi.controller.work;

import com.doubi.common.aspectj.annotation.SysLog;
import com.doubi.common.config.shiro.ShiroUtil;
import com.doubi.controller.common.BaseController;
import com.doubi.model.sys.TAdver;
import com.doubi.model.sys.TFeedback;
import com.doubi.model.sys.THelpCenter;
import com.doubi.service.FeedbackService;
import com.doubi.utils.DataUtil;
import com.doubi.vo.AppModel;
import com.doubi.vo.AppUiModel;
import com.doubi.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("feedback")
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;

    @RequiresPermissions("feedback:view")
    @GetMapping("view")
    public String view(){
        return "web/feedback/view";
    }

    @RequiresPermissions("feedback:page")
    @PostMapping("page")
    @ResponseBody
    public PageVo<TFeedback> getPage(PageVo<TFeedback> page, TFeedback feedback){
        return feedbackService.getPage(page,feedback);
    }

    @RequiresPermissions("feedback:detail")
    @GetMapping("detail")
    public String edit(TFeedback feedback, Model model) {
        if (DataUtil.isNotEmpty(feedback.getOid())) {
            feedback = feedbackService.getById(feedback.getOid());
        }
        model.addAttribute("bean", feedback);
        return "web/feedback/edit";
    }


    @SysLog(title = "反馈处理")
    @RequiresPermissions("feedback:handle")
    @GetMapping("handle")
    public String handle(TFeedback feedback, Model model) {
        if (DataUtil.isNotEmpty(feedback.getOid())) {
            feedback = feedbackService.getById(feedback.getOid());
        }
        model.addAttribute("bean", feedback);
        return "web/feedback/handle";
    }

    @SysLog(title = "处理反馈信息")
    @RequiresPermissions("feedback:updateHandleBean")
    @PostMapping("updateHandleBean")
    @ResponseBody
    public AppModel updateHandleBean(TFeedback feedback){
        return feedbackService.updateHandleBean(feedback, ShiroUtil.getUserId());
    }

    @GetMapping("getHomeStatistics")
    @ResponseBody
    public AppModel getHomeStatistics(){
        return feedbackService.getHomeStatistics();
    }
}
